<?php
require_once ("../src/db/connectdatabase.php");

function getApplyWebs() {
	$con = new ConnectDB();
	
	$tbl = "registry_apply_web";
	$fn = array('id', 'name', 'content', 'isread', 'dateregis');
	$condetion = array('delFlg' => 0);
	$flike = array();
	return $con -> getvalueall($tbl, $fn, $condetion, $flike, 'dateregis');
}

function int_to_date($int) {
    $time  = date("d/m/Y", $int);
    return $time;
}

$arrData = getApplyWebs();
?>

<style>
.searchforlaisuat, .formlaisuatthecontent {
	width: 900px;
	margin-bottom: 5px;
}
.searchforlaisuat select {
	width: 170px;
	height: 30px;
	padding: 5px;
	margin-left: 5px;
	margin-right: 5px;
}

.viewlistuudaiinfo table {
	width: 900px;
	max-width: 900px;
}

table td {
	margin-top: 2px;
	border: 1px solid;
	border-radius: 2px 2px 2px 2px;
}

table td img {
	cursor: pointer;
}

.title {
	text-align: center;
	background-color: #0088cc;
	min-height: 40px;
	-moz-border-radius: 8px 8px 0px 0px;
	-webkit-border-radius: 8px 8px 0px 0px;
	border-radius: 8px 8px 0px 0px;
	color: #FFF;
}

.stylenameproduct {
	padding-left: 5px;
	padding-right: 5px;
	width: 150px;
	max-width: 150px;
}

.stylelogobank {
	width: 100px;
	text-align: center;
	max-width: 100px;
}

.stylegiamgia {
	width: 60px;
	text-align: center;
	max-width: 60px;
}

.styletimeth {
	width: 130px;
	text-align: center;
	max-width: 130px;
}

.styleacction {
	width: 80px;
	text-align: center;
	max-width: 80px;
}

.styledatecreateth {
	width: 100px;
	max-width: 100px;
	text-align: center;
}

.nameformtd {
	-moz-border-radius: 2px 2px 2px 2px;
	-webkit-border-radius: 2px 2px 2px 2px;
	border-radius: 2px 2px 2px 2px;
	text-align: center;
}

table tr:hover td {
	background: #FFC;
}

.stylestt {
	width: 40px;
}
</style>
<h3>Danh Sách Đăng Ký Từ Web</h3>
<div style="color: red;">
<?php
	if(isset($_GET['mess'])) {
		echo($_GET['mess']);
	}
?>
</div>
<div class="viewlistuudaiinfo">
	<form action="../src/control/adminApplyWebDelAll.php" method="post" onsubmit="return confirm('Bạn có muốn xóa danh sách đã chọn?');">
    <div><input type="hidden" name="acc" value="del" /><input type="submit" value="Xóa Danh Sách Đã Chọn" style="border-radius: 5px; padding:5px; width:200px; background:#03F; color:#FFF; font-weight:bold;" /></div><br />
	<table>
    	<tr>
        	<th class="title" style="width:10px;"><input type="checkbox" class="checkall" title="Chọn Tất Cả" /></th>
            <th class="stylestt title">STT</th>
        	<th class="stylenameproduct title">Tên khách hàng</th>
            <th class="styledatecreateth title">Chưa đọc</th>
            <th class="styledatecreateth title">Ngày đăng ký</th>
            <th class="styleacction title">Chức năng</th>
        </tr>
        <?php
		if(count($arrData) > 0) {
			$i = 0;
			foreach($arrData as $entry) {
				$i++;
		?>
        <tr style=" <?php if($entry[3] == 0) { ?> background-color: #3C6 <?php } else { echo ("background: url(../images/bg-login.png);"); } ?>">
        	<td class="nameformtd"><input title="Chọn để xóa" type="checkbox" value="<?php echo($entry[0]) ?>" name="deluudai[]" class="linecheckall" /></td>
        	<td class="nameformtd" align="left"><?php echo($i) ?></td>
        	<td class="nameformtd" align="left"><?php echo($entry[1]) ?></td>
        	<td class="nameformtd" align="left"><?php if($entry[3] == 0) { echo('Chưa đọc'); } else {echo('Đã đọc'); } ?></td>
            <td class="nameformtd"><?php echo(int_to_date($entry[4])) ?></td>
            <td class="nameformtd"><img class="class-edituudai-link" src="../images/icon-edit.gif" title="Xem chi tiết <?php echo($entry[1]) ?>" idedit="<?php echo($entry[0]) ?>" />&nbsp; | &nbsp;<img class="class-deleteuudai-link" src="../images/icon-delete.gif" title="Xóa <?php echo($entry[1]) ?>" idedit="<?php echo($entry[0]) ?>" /></td>
        </tr>
        <?php
			}
		} else {
		?>
        <tr><th colspan="5">Chưa có đăng ký nào trong danh sách</th></tr>
        <?php	
		}
		?>
    </table>
    <br />
    <div><input type="hidden" name="acc" value="del" /><input type="submit" value="Xóa Danh Sách Đã Chọn" style="border-radius: 5px; padding:5px; width:200px; background:#03F; color:#FFF; font-weight:bold;" /></div>
    </form>
</div>

<script>
$(document).on('click', '.class-edituudai-link', function(e) {
	elem = $(this)
	var id = elem.attr("idedit");
	window.location= 'admin.php?content=apply-from-web&&as=detail&&id=' + id;
});

$(document).on('click', '.class-deleteuudai-link', function(e) {
	elem = $(this)
	var id = elem.attr("idedit");
	if(confirm("Bạn có muốn xóa?")) {
		$.ajax({
			url: "../src/ajax/ajaxApplyWeb.php",
			type: "post",
			data: {act:'del', idre: id},
			dataType:"json",
			success: function(data) {
				if(data == true) {
					elem.parent().parent().fadeOut(300, function(){elem.parent().parent().remove();});
				} else {
					alert("Cập nhật dữ liệu không thành công");
				}
			}
		});
	}
});

$(document).on('click', '.checkall', function(e) {
	if(!$(this).is(':checked')) {
		$('.checkall').attr('title', 'Chọn Tất Cả');
		$('.linecheckall').removeAttr('checked');
	} else {
		$('.checkall').attr('title', 'Bỏ Chọn Tất Cả');
		$('.linecheckall').attr('checked', 'checked');
	}
});
/*
$('table tr td').not(':first').click(function(e) {
    temp = $(this).parent().children().children().attr('checked') + "";
	if(temp == 'undefined') {
		$(this).parent().children().children().attr('checked', 'checked');
	} else {
		$(this).parent().children().children().removeAttr('checked');
	}
});

$(document).on('click', 'table td', function(e) {
	temp = $(this).parent().children().children().attr('checked') + "";
	if(temp == 'undefined') {
		$(this).parent().children().children().attr('checked', 'checked');
	} else {
		$(this).parent().children().children().removeAttr('checked');
	}
});
*/
</script>